/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.pig4cloud.pigx.user.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.user.entity.UserApiKeyLockDetail;
import com.pig4cloud.pigx.user.service.UserApiKeyLockDetailService;
import com.pig4cloud.pigx.user.vo.UserApiKeyLockDetailLockVO;
import com.pig4cloud.pigx.user.vo.UserApiKeyLockDetailUnlockVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 用户apiKey封禁/解封记录
 *
 * @since 2022-10-28 15:47:45
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/userapikeylockdetail")
@Api(value = "userapikeylockdetail", tags = "用户apiKey封禁/解封记录管理")
public class UserApiKeyLockDetailController {

	private final UserApiKeyLockDetailService userApiKeyLockDetailService;

	/**
	 * 封禁记录分页查询
	 *
	 * @param page      分页条件
	 * @param condition 查询条件
	 * @return {@link R< Page< UserApiKeyLockDetailLockVO>>}
	 * @since 2022/10/28 18:48
	 */
	@ApiOperation(value = "封禁记录分页查询", notes = "封禁记录分页查询")
	@GetMapping("/page/lock")
	// @PreAuthorize("@pms.hasPermission('user_api_key_lock_detail_view')")
	public R<Page<UserApiKeyLockDetailLockVO>> pageLock(Page<UserApiKeyLockDetail> page, UserApiKeyLockDetail condition) {
		if (Objects.isNull(condition.getApiKeyId())) {
			throw new RuntimeException("参数异常，apiKeyId为空");
		}

		return R.ok(userApiKeyLockDetailService.pageLock(page, condition));
	}

	/**
	 * 解封记录分页查询
	 *
	 * @param page      分页条件
	 * @param condition 查询条件
	 * @return {@link R< Page< UserApiKeyLockDetailUnlockVO>>}
	 * @since 2022/10/28 18:48
	 */
	@ApiOperation(value = "解封记录分页查询", notes = "解封记录分页查询")
	@GetMapping("/page/unlock")
	// @PreAuthorize("@pms.hasPermission('user_api_key_lock_detail_view')")
	public R<Page<UserApiKeyLockDetailUnlockVO>> pageUnlock(Page<UserApiKeyLockDetail> page, UserApiKeyLockDetail condition) {
		if (Objects.isNull(condition.getApiKeyId())) {
			throw new RuntimeException("参数异常，apiKeyId为空");
		}

		return R.ok(userApiKeyLockDetailService.pageUnlock(page, condition));
	}
}
